﻿using System;
using System.IO;

namespace ToolExcelPub
{
    public static partial class XTool
    {
        //当前目录
        public static string PathCurrent = "";
        //配置目录
        public static string PathConfig = @"Config";
        //输出目录
        public static string PathOutput = @"Config";
        //表格目录
        public static string PathExcel = @"Config\Excel";
        //JsonServer目录
        public static string PathJsonServer = @"Config\JsonServer";
        //JsonClient目录
        public static string PathJsonClient = @"Config\JsonClient";
        //Json目录
        public static string PathJson = @"Config\Json";
        //Csharp目录
        public static string PathCsharp = @"Config\Csharp";
        //Ts目录
        public static string PathTs = @"Config\Ts";
        //Go目录
        public static string PathGo = @"Config\Go";


        //命名空间服务器
        public static string NamespaceServer = "namespace ServerBase.Config";
        //命名空间客户端
        public static string NamespaceClient = "namespace ConfClient";
        //生成注释
        public static string NoteGenerated = "\r\n// this file is generated by tool, don't edit!!!!!!!!!!!!!\r\n";


        //初始化目录
        public static void InitPath()
        {
            ShowInfo("InitPath!");

            PathCurrent = Directory.GetCurrentDirectory();
            PathCurrent = ToolGlobal.GetParentFolder(PathCurrent);

            PathConfig = PathCurrent + @"\" + ToolConfig.PathConfig;
            PathOutput = PathCurrent + @"\" + ToolConfig.PathOutput;
            PathExcel = PathConfig + @"\" + ToolConfig.PathExcel;
            PathJsonServer = PathOutput + @"\" + ToolConfig.PathJsonServer;
            PathJsonClient = PathOutput + @"\" + ToolConfig.PathJsonClient;
            PathJson = PathOutput + @"\" + ToolConfig.PathJson;
            PathCsharp = PathOutput + @"\" + ToolConfig.PathCsharp;
            PathTs = PathOutput + @"\" + ToolConfig.PathTs;
            PathGo = PathOutput + @"\" + ToolConfig.PathGo;
        }

        //检查目录
        public static void CheckPath()
        {
            ShowInfo("CheckPath!");

            if (!Directory.Exists(XTool.PathExcel))
            {
                ShowError($"导入文档路径< {XTool.PathExcel} >并不存在！请重新设置！", "提示");
                Console.ReadKey();
                return;
            }
            if (!Directory.Exists(XTool.PathOutput))
            {
                ShowError($"导出文档路径< {XTool.PathOutput} >并不存在！请重新设置！", "提示");
                Console.ReadKey();
                return;
            }

            if (!Directory.Exists(PathJsonServer)) { Directory.CreateDirectory(PathJsonServer); }
            if (!Directory.Exists(PathJsonClient)) { Directory.CreateDirectory(PathJsonClient); }
            if (!Directory.Exists(PathJson)) { Directory.CreateDirectory(PathJson); }
            if (OutputCsharpNeed)
            {
                if (!Directory.Exists(PathCsharp)) { Directory.CreateDirectory(PathCsharp); }
            }
            if (OutputTsNeed)
            {
                if (!Directory.Exists(PathTs)) { Directory.CreateDirectory(PathTs); }
            }
            if (OutputGoNeed)
            {
                if (!Directory.Exists(PathGo)) { Directory.CreateDirectory(PathGo); }
            }

            ToolGlobal.EmptyFolder(PathJson);
            if (OutputCsharpNeed)
            {
                ToolGlobal.EmptyFolder(PathCsharp);
            }
        }


    }
}
